// import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:fun_shop/src/ui/pages/error/error_page.dart';
import 'package:fun_shop/src/ui/pages/index/index_page.dart';
import 'package:fun_shop/src/ui/pages/splash/splash_page.dart';

final routerConfig = GoRouter(
  initialLocation: '/splash',
  // redirect: (context, state) {
  //   print(state.uri);
  //   if (state.uri.toString() == '/') {
  //     return '/index';
  //   }
  //   return null;
  // },

  errorBuilder: (context, state) {
    // 确保 state.error 不为空，否则提供一个默认的 GoException 实例
    final error = state.error ?? GoException('默认错误信息');
    // 移除 const 关键字
    return ErrorPage(error);
  },

  routes: [
    GoRoute(
      path: '/splash',
      name: 'splash',
      builder: (context, state) => const SplashPage(),
    ),
    GoRoute(
      path: '/index',
      name: 'index',
      builder: (context, state) => const IndexPage(),
    )
  ]
);